﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using ESoft.Core.DataAccess.Entity;
using ESoft.Core.Web.VO;

namespace ESoft.Core.DataAccess.DAO
{
    public interface IBaseDao
    {
        T Find<T>(object id) where T : BaseModel, new();
        Task<T> FindAsync<T>(object id) where T : BaseModel, new();
        Task<T> FirstOrDefaultAsync<T>(Expression<Func<T, bool>> predicate) where T : BaseModel, new();

        T First<T>(Expression<Func<T, bool>> predicate) where T : BaseModel, new();
        T Add<T>(T entity) where T : BaseModel, new();
        Task<T> AddAsync<T>(T entity) where T : BaseModel, new();
        bool Update<T>(T entity) where T : BaseModel, new();
        Task<T> UpdateAsync<T>(T entity) where T : BaseModel, new();
        bool Delete<T>(object id) where T : BaseModel, new();
        bool Delete<T>(T entity) where T : BaseModel, new();
        bool Delete<T>(IEnumerable<T> entities) where T : BaseModel, new();
        bool Exist<T>(Expression<Func<T, bool>> predicate) where T : BaseModel, new();
        int Count<T>(Expression<Func<T, bool>> predicate) where T : BaseModel, new();
        Task<int> CountAsync<T>(Expression<Func<T, bool>> predicate) where T : BaseModel, new();
        int Sum<T>(Expression<Func<T, bool>> predicate, Expression<Func<T, int>> selector) where T : BaseModel, new();
        decimal Sum<T>(Expression<Func<T, bool>> predicate, Expression<Func<T, decimal>> selector) where T : BaseModel, new();

        Task<int> SumAsync<T>(Expression<Func<T, bool>> predicate, Expression<Func<T, int>> selector)
            where T : BaseModel, new();

        IQueryable<T> LoadEntities<T>() where T : BaseModel, new();
        Task<List<T>> LoadEntitiesAsync<T>() where T : BaseModel, new();

        List<T> LoadEntities<T>(Expression<Func<T, bool>> predicate) where T : BaseModel, new();

        Task<List<T>> LoadEntitiesAsync<T>(Expression<Func<T, bool>> predicate) where T : BaseModel, new();

        IQueryable<T> LoadPageEntities<T>(PageInput page, Expression<Func<T, bool>> predicate, SortVo sort)
            where T : BaseModel, new();
    }
}
